package com.lagou.dao;

import com.lagou.domain.Student;
import com.lagou.util.JDBCUtils;
import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.Connection;
import java.sql.SQLException;

public class AddDao {
    public static int add(Student student) throws SQLException {
        QueryRunner queryRunner = new QueryRunner();
        String sql = "insert into student(id,stuno,stuname,stusex,stubir) values(?,?,?,?,?)";
        Object[] params = {null,student.getStuno(),student.getStuname(),student.getStusex(),student.getStubir()};
        Connection con = JDBCUtils.getConnection();
        int count =0;
        try {
             count = queryRunner.update(con,sql,params);
//            con.close();
            DbUtils.close(con);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return count;
    }
}
